package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class UploadController {

    @RequestMapping("upload")
    public String upload(@RequestParam("uploadImg") MultipartFile mf) throws IOException {
        //得到文件名
        String fileName = mf.getOriginalFilename();
        //以时间毫秒数 重命名上传文件，防止因上传文件同名而导致的覆盖。
        fileName = System.currentTimeMillis() + fileName.substring(fileName.lastIndexOf("."));
        //将上传文件的二进制数据写入指定文件
        mf.transferTo(new File("D:\\JavaPlus\\javaWEB\\DormitoryManagementSystem\\src\\main\\java\\com\\project\\faceImg" + fileName));

        return fileName;
    }
}
